//
// Created by zhupi on 2024/8/31.
//

#include "project_dock.h"

#include <QHBoxLayout>

void ProjectDock::Initial()
{
    this->setMinimumWidth(200);
    InitWidget();
    InitTree();
}

void ProjectDock::InitWidget() {

    dockWidget_ = new QWidget(this);
    this->setWidget(dockWidget_);

    QHBoxLayout *mainHbox = new QHBoxLayout(this);
    mainHbox->setContentsMargins(0,5,0,0);
    treeView_ = new DockTree(dockWidget_);
    mainHbox->addWidget(treeView_);
    dockWidget_->setLayout(mainHbox);

}

void ProjectDock::InitTree() {
    // 创建一个标准项模型
    treeMolde_ = new QStandardItemModel;

    // 设置列标题
    treeMolde_->setHorizontalHeaderLabels(QStringList() << "Item" << "Description");

    // 创建根节点
    QStandardItem *rootItem = treeMolde_->invisibleRootItem();

    // 创建一些项
    QStandardItem *item1 = new QStandardItem("Item 1");
    QStandardItem *item2 = new QStandardItem("Item 2");
    QStandardItem *item3 = new QStandardItem("Item 3");

    // 为每个项添加子项
    item1->appendRow(new QStandardItem("SubItem 1.1"));
    item1->appendRow(new QStandardItem("SubItem 1.2"));
    item2->appendRow(new QStandardItem("SubItem 2.1"));
    item3->appendRow(new QStandardItem("SubItem 3.1"));
    item3->appendRow(new QStandardItem("SubItem 3.2"));

    // 将项添加到根节点
    rootItem->appendRow(item1);
    rootItem->appendRow(item2);
    rootItem->appendRow(item3);

    // 将模型设置到QTreeView
    treeView_->setModel(treeMolde_);

    // 设置QTreeView的样式表，显示网格线
    treeView_->setStyleSheet(
            "QTreeView::item {"
            "    border: 1px solid lightgray;"
            "}"
    );

    // 调整列宽
//    treeView_->header()->setSectionResizeMode(QHeaderView::ResizeToContents);

    // 显示QTreeView
    treeView_->setWindowTitle("QTreeView Example");
//    treeView_->resize(400, 300);
    treeView_->show();

}


